package com.loyal.loyalerp.basedata.department.utils.jsonserializer;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.loyal.loyalerp.basedata.department.mapper.DepartmentMapper;
import com.loyal.loyalerp.basedata.department.model.Department;
import com.loyal.loyalerp.basedata.department.service.DepartmentService;

@Component
public class ParentIdJsonSerializer extends JsonSerializer<Integer>{

	@Autowired
	private DepartmentService deptService;
	@Override
	public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
			throws IOException, JsonProcessingException {
		Department dept=deptService.selectByPrimaryKey(value);
		if(dept==null)
			gen.writeString("root");
		else
			gen.writeString(dept.getDeptName());
		
	}


}
